Skip to content

Conversation

@maparent
Copy link
Collaborator

@maparent maparent commented Dec 16, 2025

https://linear.app/discourse-graphs/issue/ENG-1121/endsynctask-error-wrong-worker

Summary by CodeRabbit

Release Notes

  • New Features
    • Added last successful sync timestamp tracking to synchronization information.
    • Implemented enhanced sync task management with timeout handling and status progression for improved task coordination.

✏️ Tip: You can customize this high-level summary in your review settings.

@linear
Copy link

linear bot commented Dec 16, 2025

@supabase
Copy link

supabase bot commented Dec 16, 2025

Updates to Preview Branch (eng-1121-endsynctask-error-wrong-worker) ↗︎

Deployments Status Updated
Database Wed, 17 Dec 2025 01:40:59 UTC
Services Wed, 17 Dec 2025 01:40:59 UTC
APIs Wed, 17 Dec 2025 01:40:59 UTC

Tasks are run on every commit but only new migration files are pushed.
Close and reopen this PR if you want to apply changes from existing seed or migration files.

Tasks Status Updated
Configurations Wed, 17 Dec 2025 01:41:00 UTC
Migrations Wed, 17 Dec 2025 01:41:02 UTC
Seeding Wed, 17 Dec 2025 01:41:02 UTC
Edge Functions Wed, 17 Dec 2025 01:41:06 UTC

View logs for this Workflow Run ↗︎.
Learn more about Supabase for Git ↗︎.

@maparent
Copy link
Collaborator Author

@CodeRabbit review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 16, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 16, 2025

📝 Walkthrough

Walkthrough

These changes extend the sync_info table with a new last_success_start timestamp field and update database functions to track and propagate this field through sync task proposal and completion workflows, with data migration and TypeScript type updates.

Changes

Cohort / File(s) Change Summary
TypeScript type definitions
packages/database/src/dbTypes.ts
Added last_success_start: string | null field to sync_info table Row, Insert, and Update type definitions
Database migration
packages/database/supabase/migrations/20251216222945_sync_last_success_start.sql
Added last_success_start column to sync_info table; made last_task_start NOT NULL; backfilled last_success_start data; introduced end_sync_task() and propose_sync_task() functions with task status management, timeout/backoff logic, and state transitions
Database schema definitions
packages/database/supabase/schemas/sync.sql
Updated sync_info table schema (added last_success_start column, enforced last_task_start NOT NULL); updated end_sync_task() and propose_sync_task() function implementations to handle the new field through selection, calculation, and update operations

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Key areas requiring attention:

  • SQL logic in propose_sync_task(): timeout calculation, backoff computation, task advancement conditions, and return value selection based on last_success_start
  • SQL logic in end_sync_task(): status transition validation, assertion checks, conditional updates for complete vs. non-complete status, and failure count handling
  • Data migration backfill logic: ensure correctness of populating last_success_start from last_task_end conditionals
  • Consistency alignment between migration file and schema file function implementations
  • TypeScript types alignment with database column definitions

Possibly related PRs

Pre-merge checks

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'ENG-1121 endSyncTask error - wrong worker' is vague and does not clearly convey the actual changes in the PR, which add a new last_success_start field and introduce sync task management functions. Consider revising the title to reflect the main changes: 'Add last_success_start tracking to sync_info schema and implement sync task management functions' or similar, to better describe what was actually implemented.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/database/supabase/schemas/sync.sql (1)

127-134: Consider using last_success_start directly for consistency.

For a newly inserted row, last_success_start is NULL (no previous successful completion). The current query (lines 130-133) will also return NULL since the row was just inserted with status='active'.

While functionally correct, the existing-row path returns t_last_success_start directly (line 154). For consistency, the new-row path could simply return NULL without the query.

     IF s_id IS NOT NULL THEN
         -- totally new_row, I'm on the task
         -- return last time it was run successfully
-        SELECT max(last_task_start) INTO result FROM public.sync_info
-            WHERE sync_target = s_target
-            AND sync_function = s_function
-            AND status = 'complete';
-        RETURN result;
+        RETURN NULL;  -- new task has no previous successful run
     END IF;
📜 Review details

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 373aeaf and 74643db.

📒 Files selected for processing (3)
  • packages/database/src/dbTypes.ts (3 hunks)
  • packages/database/supabase/migrations/20251216222945_sync_last_success_start.sql (1 hunks)
  • packages/database/supabase/schemas/sync.sql (6 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/main.mdc)

**/*.{ts,tsx}: Use Tailwind CSS for styling where possible
When refactoring inline styles, use tailwind classes
Prefer type over interface in TypeScript
Use explicit return types for functions
Avoid any types when possible
Prefer arrow functions over regular function declarations
Use named parameters (object destructuring) when a function has more than 2 parameters
Use PascalCase for components and types
Use camelCase for variables and functions
Use UPPERCASE for constants
Function names should describe their purpose clearly
Prefer early returns over nested conditionals for better readability

Files:

  • packages/database/src/dbTypes.ts
🧠 Learnings (5)
📚 Learning: 2025-06-09T16:57:14.681Z
Learnt from: maparent
Repo: DiscourseGraphs/discourse-graph PR: 198
File: packages/database/supabase/migrations/20250605083319_alpha_upload.sql:157-337
Timestamp: 2025-06-09T16:57:14.681Z
Learning: Migration files in packages/database/supabase/migrations/ are historical snapshots that preserve database schema and functions as they existed at the time of creation. These files should not be updated to reflect current schema changes, even if they reference tables or columns that have since been modified or removed. Schema incompatibilities in migration files are expected and acceptable as they represent the valid state at the time of migration.

Applied to files:

  • packages/database/supabase/migrations/20251216222945_sync_last_success_start.sql
  • packages/database/supabase/schemas/sync.sql
📚 Learning: 2025-05-20T03:04:21.602Z
Learnt from: maparent
Repo: DiscourseGraphs/discourse-graph PR: 165
File: packages/database/supabase/migrations/20250512142307_sync_table.sql:20-21
Timestamp: 2025-05-20T03:04:21.602Z
Learning: Database migration files (like the SQL files in packages/database/supabase/migrations/) should not be modified after they're created, even to fix minor issues like unused variables. Issues should be addressed in newer schema files instead to maintain migration history integrity.

Applied to files:

  • packages/database/supabase/migrations/20251216222945_sync_last_success_start.sql
  • packages/database/supabase/schemas/sync.sql
📚 Learning: 2025-05-22T23:50:23.771Z
Learnt from: maparent
Repo: DiscourseGraphs/discourse-graph PR: 165
File: packages/database/supabase/migrations/20250513173724_content_concept_key.sql:37-60
Timestamp: 2025-05-22T23:50:23.771Z
Learning: For the discourse-graph project, database schema management focuses on the final state in the supabase/schemas directory, not on the individual migration files. When reviewing database changes, consider only the schema definitions in this directory, not potential duplications or conflicts across migration files.

Applied to files:

  • packages/database/supabase/migrations/20251216222945_sync_last_success_start.sql
  • packages/database/supabase/schemas/sync.sql
📚 Learning: 2025-05-20T03:01:11.220Z
Learnt from: maparent
Repo: DiscourseGraphs/discourse-graph PR: 165
File: packages/database/supabase/migrations/20250504195841_remote_schema.sql:1-7
Timestamp: 2025-05-20T03:01:11.220Z
Learning: Supabase automatically creates necessary schemas like the "extensions" schema before migrations run, so there's no need to explicitly create these schemas in migration files.

Applied to files:

  • packages/database/supabase/migrations/20251216222945_sync_last_success_start.sql
  • packages/database/supabase/schemas/sync.sql
📚 Learning: 2025-05-20T03:11:07.917Z
Learnt from: maparent
Repo: DiscourseGraphs/discourse-graph PR: 165
File: packages/database/supabase/migrations/20250504202930_content_tables.sql:37-45
Timestamp: 2025-05-20T03:11:07.917Z
Learning: When reviewing SQL migrations in this codebase, understand that historical migration files should not be modified once they're applied. Instead, issues should be fixed in subsequent migrations or schema definition files. This is why maparent indicated "migration, not changing. corrected in schema."

Applied to files:

  • packages/database/supabase/migrations/20251216222945_sync_last_success_start.sql
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Supabase Preview
🔇 Additional comments (6)
packages/database/src/dbTypes.ts (1)

639-680: LGTM!

The auto-generated type definitions correctly reflect the new last_success_start column: nullable in Row, optional and nullable in Insert and Update. Properly aligned with the SQL schema.

packages/database/supabase/schemas/sync.sql (2)

18-21: LGTM!

Schema changes are appropriate: last_task_start is correctly NOT NULL (every task must have a start time), while last_success_start is nullable since new tasks haven't completed successfully yet.


49-90: LGTM!

The end_sync_task function correctly tracks last_success_start:

  • On completion (line 74): captures the current task's start time as the last successful start
  • On failure/timeout: preserves the existing last_success_start value
  • The worker assertion (line 70) properly guards against task completion by the wrong worker
packages/database/supabase/migrations/20251216222945_sync_last_success_start.sql (3)

1-7: LGTM!

The migration correctly:

  1. Adds the nullable last_success_start column
  2. Enforces NOT NULL on last_task_start
  3. Backfills last_success_start from last_task_start for rows with last_task_end set (which indicates successful completion)

The backfill condition is correct since last_task_end is only populated when end_sync_task is called with status='complete'.


8-46: LGTM!

The end_sync_task function correctly implements the state tracking for successful task completions. The logic properly updates last_success_start only when status is 'complete'.


49-120: LGTM!

The propose_sync_task function now correctly returns t_last_success_start (line 98) when taking over an existing task, enabling callers to accurately track successful sync progress rather than just task attempts.

@maparent maparent force-pushed the eng-1121-endsynctask-error-wrong-worker branch from db88a16 to b6d316f Compare December 17, 2025 01:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants